#pragma once

#include <QWidget>
#include <QListWidget>
#include "util/serverhelper.h"
#include "util/usermanager.h"
#include "poco/vocabulary.h"
#include "page/dictationdialog.h"

namespace Ui {
class VocabularyWordsPage;
}

namespace WordMemory
{
    class VocabWordsPage : public QWidget
    {
        Q_OBJECT

    public:
        explicit VocabWordsPage(const Vocabulary &vocabulary, QWidget *parent = nullptr);
        ~VocabWordsPage();

    signals:
        void backToStudyPage();
        void wordSelected(const QString& word);
        void addWordToMistakes(const Word& word);
        void dictatingDoneRefreshVocabList();

    private slots:
        void on_backButton_clicked();
        void on_wordsListWidget_itemClicked(QListWidgetItem *item);
        void on_dictationButton_clicked();

        void handleDownloadButtonClicked(const Word& word, QPushButton* button);
        void handleWordItemClicked(const Word& word);

    private:
        void setupStyles();
        void setupConnections();
        void refreshWords();
        void populateWordsList(const QList<Word> &words);

        void startNextDictationWord();
        void endDictationSession();

        Ui::VocabularyWordsPage *ui;
        ServerHelper* serverhelper;

        Vocabulary vocabulary;

        QList<Word> wordsForDictation;
        QList<Word> dictationQueue;
        int currentDictationIndex;

        DictationDialog* dictationDialog;
    };
}
